<template>
	<view>
		<view v-if="azjgs">
			<view class="flex justify-between align-center padding-sm">
				<view>
					<text class="text-bold">公司名称：</text>
					<text>{{azjgs.zjgsnc ? azjgs.zjgsnc : '未设定名称'}}</text>
				</view>
				<view v-if="isZjfzr" class="flex justify-between align-center">
					
					<button @tap="editZjgs" size="mini">编辑</button>
				</view>
			</view>
			<view class="flex justify-between align-center padding-sm">
				<text class="text-bold">佣金合计：</text>
				<text>￥{{acommission ? acommission.total / 100 : 0}}</text>
			</view>
			<view class="flex justify-between align-center padding-sm">
				<text class="text-bold">区域：</text>
				<text>
					<text class="" v-if="azjgs.pcode">{{locamap.cmap[azjgs.pcode].criname}}</text>
					<text class="" v-if="azjgs.scode">{{locamap.cmap[azjgs.scode].criname}}</text>
					<text class="" v-if="azjgs.qcode">{{locamap.cmap[azjgs.qcode].criname}}</text>
				</text>
			</view>
			<view class="flex justify-between align-center padding-sm">
				<text class="text-bold">地址：</text>
				<text>{{azjgs.dz ? azjgs.dz : '未设定地址'}}</text>
			</view>

			<view class="margin-top-sm">
				<view class="padding-xs w-25 inline-block">
					<view @tap="toMd" class="flex flex-direction align-center relative bg-yellow radius shadow padding-sm">
						<text class="text-sl">
							<text class="iconfont icon-8"></text>
						</text>
						<text class="text-sm">门店数量</text>
						<text style="top: -2rpx; right: -2rpx;"
							class="bg-red text-xs round absolute padding-xxs">{{sCount}}</text>
					</view>
				</view>
				<view class="padding-xs w-25 inline-block">
					<view @tap="toYj" class="flex flex-direction align-center relative bg-yellow radius shadow padding-sm">
						<text class="text-sl">
							<text class="iconfont icon-fenchengbili"></text>
						</text>
						<text class="text-sm">佣金明细</text>
						<text style="top: -2rpx; right: -2rpx;"
							class="bg-red text-xs round absolute padding-xxs">{{cCount}}</text>
					</view>
				</view>
				<view v-if="isZjfzr" class="padding-xs w-25 inline-block">
					<view @tap="toSqjl" class="flex flex-direction align-center relative bg-yellow radius shadow padding-sm">
						<text class="text-sl">
							<text class="iconfont icon-daikeyuyue"></text>
						</text>
						<text class="text-sm">申请记录</text>
						<text style="top: -2rpx; right: -2rpx;"
							class="bg-red text-xs round absolute padding-xxs">{{sqCount}}</text>
					</view>
				</view>
				<view v-if="isZjfzr" class="padding-xs w-25 inline-block">
					<view @tap="toYwyjl" class="flex flex-direction align-center relative bg-yellow radius shadow padding-sm">
						<text class="text-sl">
							<text class="iconfont icon-zuidapaiduishu"></text>
						</text>
						<text class="text-sm">业务员</text>
						<text style="top: -2rpx; right: -2rpx;"
							class="bg-red text-xs round absolute padding-xxs">{{ywyCount}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="padding" v-else>
			<button @tap="registZjgs" class="cu-btn block bg-yellow lg">注册中介公司</button>
		</view>
		<zjgs-edit v-if="showEdit" v-model="zjgs" @close="closeEdit"></zjgs-edit>
	</view>
</template>

<script>
	import zjgsEdit from "./zjgs/edit.vue";
	export default {
		components: {
			"zjgs-edit": zjgsEdit,
		},
		data: function() {
			return {
				showEdit: false,
				locamap: {},
				fzzj: {
					zjid: "",
					zjname: "",
					openid: "",
					tel: "",
					clientid: "",
					commissionid: "",
					zjgsid: "",
				},
				azj: this.store.state.zj,
				acommission: undefined,
				azjgs: this.store.state.zjgs,
				cCount: 0,
				sCount: 0,
				sqCount: 0,
				ywyCount: 0,
				zjgs: undefined,
				
			};
		},
		created: function() {
			this.locamap = this.location.localmap;
			if (this.azjgs) {
				this.loadZgsj();
			}
		},
		computed: {
			isZjfzr: function() {
				if (this.azj && this.azjgs && this.azj.zjid == this.azjgs.fzzjid) {
					return true;
				}
				return false;
			}
		},
		methods: {
			editZjgs: function() {
				this.zjgs = this.azjgs;
				this.showEdit = true;
			},
			registZjgs: function() {
				this.zjgs = {
					zjgsid: "",
					zjgsnc: "",
					dz: "",
					fzzjid: "",
					pcode: "",
					scode: "",
					qcode: "",
				};
				this.showEdit = true;
			},
			closeEdit: function() {
				this.zjgs.fzzjid = this.azj.zjid;
				this.api("/zj/zjgs/info").send({
					azjgs: this.zjgs
				}).then(data => {
					this.showEdit = false;
					this.azjgs = data.azjgs;
					this.store.commit("submitZjgs", data.azjgs);
					this.zjgs = undefined;
					if (data.azj) {
						this.azj = data.azj;
						this.store.commit("submitZj", data.azj);
					}
					this.loadZgsj();
					this.message.info("保存成功");
				});
			},
			loadZgsj: function() {
				this.api("/zj/zjgs/info/get").send({
					zjgsid: this.azjgs.zjgsid
				}).then(data => {
					this.acommission = data.acommission;
					this.cCount = data.cCount;
					this.sCount = data.sCount;
					this.sqCount = data.sqCount;
					this.ywyCount = data.ywyCount;
				});
			},
			toMd: function() {
				uni.navigateTo({
					url: '/pages/czj/md/list?zjgsid='+this.azjgs.zjgsid
				});
			},
			toYj: function() {
				uni.navigateTo({
					url: '/pages/czj/yj/list?zjgsid='+this.azjgs.zjgsid
				});
			},
			toSqjl: function() {
				uni.navigateTo({
					url: '/pages/czj/zjsq/list?zjgsid='+this.azjgs.zjgsid
				});
			},
			toYwyjl: function() {
				uni.navigateTo({
					url: '/pages/czj/ywy/list?zjgsid='+this.azjgs.zjgsid
				});
			}
		}
	}
</script>

<style>
</style>